import http from "@/api";

// 登录模块
export namespace Login {
  export interface ReqLoginForm {
    username: string;
    password: string;
  }
  export interface ReqChangePassword {
    oldPassword: string;
    newPassword: string;
  }
  export interface ResLogin {
    token: string;
    userInfo: {
      userId: string;
      username: string;
      avatar: string;
      nickname: string;
    };
  }
  export interface ResAuthButtons {
    [key: string]: string[];
  }
}
// 用户登录
export const loginApi = (params: Login.ReqLoginForm) => {
  return http.post<Login.ResLogin>("/admin/login", params, { loading: false });
};

// 获取菜单列表
export const getAuthMenuListApi = () => {
  return http.get<Menu.MenuOptions[]>("/admin/getMenus", {}, { loading: false });
};

// 用户退出登录
export const logoutApi = () => {
  return http.delete("/admin/logout");
};
// 用户修改密码
export const changePasswordApi = (params: Login.ReqChangePassword) => {
  return http.post("/admin/changePassword", params);
};
export const getAuthButtonListApi = () => {
  return http.get<Login.ResAuthButtons>("/admin/getAuthElement", {}, { loading: false });
};

export const forceLogout = (token: string) => {
  return http.delete("/admin/forceLogout", { token });
};